package com.zgkxzx.数据结构.链表;

/**
 * 创建者 zgkxzx
 * 日期   1/26/18
 * 描述
 */

public class ZLinkList<T> {
    private LinkListEntity<T> head;
    private LinkListEntity<T> currentEntity;

    public ZLinkList() {

    }

    /**
     * 添加一个元素
     *
     * @param t
     */
    public void add(T t) {
        if (head == null) {
            head = new LinkListEntity<>(t);
            currentEntity = head;
        } else {
            currentEntity.next = new LinkListEntity<>(t);
            currentEntity = currentEntity.next;
        }
    }


    public void print() {
        if (head == null)
            return;
        else {
            LinkListEntity<T> temp = head;
            while (temp != null) {
                System.out.println("遍历值" + temp.value);
                temp = temp.next;
            }
        }
    }


    public int find(T t) {
        if (head == null)
            return -1;
        else {
            int ret = -1;
            LinkListEntity<T> temp = head;

            while (temp != null) {
                if (temp.value == t){
                    ret = temp.index;
                    break;
                }
                temp = temp.next;
            }
            return ret;
        }

    }


    public static class LinkListEntity<T> {
        public LinkListEntity next;
        public int index;
        public T value;

        public LinkListEntity(T value) {
            this.value = value;
        }
    }
}
